Home:ALL Converter>Adding to Dictionary does not add

Adding to Dictionary does not add

Ask Time:2015-03-31T03:20:23         Author:Scavs

Json Formatter

I have Dictionary which contains string as key and System.Object as value.

Dictionary<string, System.Object> test = new Dictionary<string, System.Object>();

I create and add values

Debug.Log("Key:" + (string)KEY.obj);
Debug.Log("VALUE:" + (string)VALUE.obj);

test.Add((string)KEY.obj, VALUE.obj);

if (test.ContainsKey("id")){
    Debug.Log("contains!");
}
else{
    Debug.Log("does not contain!");
}

Debug Console

enter image description here

KEY and VALUE is an object of class

private sealed class ResolveValue {

    public readonly System.Object obj;
    public readonly int end;

    public ResolveValue(System.Object obj, int end){
        this.obj = obj;
        this.end = end;
    }
}

Where KEY is "id" and VALUE is "myData".

Took me quite a while to find the problem. How is this possible?

Additional information

All string are converter from bytes. Here's a debug i made.

Debug.Log("--------");

string msg = "";
foreach(byte b in bytes){
    msg += b + " ";
}
Debug.Log(msg);

Debug.Log("--------");

string message = System.Text.Encoding.UTF8.GetString(bytes);
Debug.Log(message);

ResolveValue response = new ResolveValue(message, end);

Variable end is an integer and has nothing to do with this problem.

enter image description here

Author:Scavs,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29354455/adding-to-dictionary-does-not-add
yy